package leetcode;

import java.util.HashSet;
import java.util.Set;

import common.ListNode;

public class LeetCode141_2 {
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) return false;
        Set<ListNode> listnodes = new HashSet<>();
        while (head != null) {
            if (listnodes.contains(head)) return true;
            listnodes.add(head);
            head = head.next;
        }
        return false;
    }
}